package edu.nf.relaxenjoy.web.controller.app;

import com.github.pagehelper.PageInfo;
import edu.nf.relaxenjoy.common.result.ResultVO;
import edu.nf.relaxenjoy.domain.entity.User;
import edu.nf.relaxenjoy.domain.vo.FollowVo;
import edu.nf.relaxenjoy.domain.vo.TrendVo;
import edu.nf.relaxenjoy.domain.vo.UserRecordVo;
import edu.nf.relaxenjoy.domain.vo.UserVo;
import edu.nf.relaxenjoy.service.UserService;
import edu.nf.relaxenjoy.web.controller.BaseController;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhu
 * @date 2024-12-20
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/user")
@Api(tags="用户模块")
public class UserController extends BaseController {

    private final UserService userService;

    /**
     * 得到当前用户的所有动态
     *
     * @param page
     * @param limit
     * @param userId
     * @return
     */
    @RequestMapping("/getTrendByUser/{page}/{limit}")
    public ResultVO getTrendByUser(@PathVariable long page, @PathVariable long limit, @RequestParam("userId") Long userId, @RequestParam("type")Integer type) {
        PageInfo<TrendVo> pageInfo = userService.getTrendByUser(page, limit, userId, type);
        return success(pageInfo);
    }

    /**
     * 获取用户信息
     *
     * @param uid
     * @return
     */
    @RequestMapping("getUserInfo")
    public ResultVO getUserInfo(@RequestParam("uid") Long uid) {
        return success(userService.getById(uid));
    }

    /**
     * 更新用户信息
     *
     * @param user
     * @return
     */
    @RequestMapping("updateUser")
    public ResultVO updateUser(@RequestBody User user) {
        return success(userService.updateUser(user));
    }

    /**
     * 查找用户信息
     *
     * @param keyword
     * @return
     */
    @RequestMapping("searchUser/{page}/{limit}")
    public ResultVO searchUser(@PathVariable long page, @PathVariable long limit, String keyword, String uid) {
        PageInfo<FollowVo> pageInfo = userService.searchUser(page, limit, keyword, uid);
        return success(pageInfo);
    }

    /**
     * 用户名精确查找
     *
     * @param keyword
     * @return
     */
    @RequestMapping("searchUserByUsername")
    public ResultVO searchUserByUsername(String keyword) {
        List<UserVo> userVoList = userService.searchUserByUsername(keyword);
        return success(userVoList);
    }

    @RequestMapping("getUserRecord")
    public ResultVO getUserRecord(String uid) {
        UserRecordVo userRecordVo = userService.getUserRecord(uid);
        return success(userRecordVo);
    }

    /**
     * 清除用户记录
     *
     * @param uid
     * @param type
     * @return
     */
    @RequestMapping("clearUserRecord")
    public ResultVO clearUserRecord(String uid, Integer type) {
        userService.clearUserRecord(uid, type);
        return success();
    }

}
